package com.example.mvel;

import org.junit.Test;
import org.mvel.MVEL;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Date 2023-05-12
 * @Author Jonathan
 */
public class MvelDemoTest {
    @Test
    public void t1() {
        System.out.println("hello world");
//        while (true) {
//            Serializable compiledExpression = MVEL.compileExpression("hasRecallType(259) || hasRecallType(261)");
//            for (int i = 0; i < 300; i++) {
//                expressionContext.reset(i);
//                MVEL.executeExpression(compiledExpression, expressionContext);
//            }
//            sleep(10);
//        }
    }

    @Test
    public void test() {
        String expression = "foobar > 99";
        Map<String, Integer> vars = new HashMap<>();
        vars.put("foobar", 100);

        // We know this expression should return a boolean.
        // MVEL.eval()

        Boolean result = (Boolean) MVEL.eval(expression, vars);
        if (result) {
            System.out.println("Itworks!");
        }
    }

}
